<?php
namespace app\controller;

use think\facade\Db;
use think\facade\Request;

class Announcement
{
    public function getLatest()
    {
        $announcement = Db::name('announcements')->order('created_at', 'desc')->find();
        
        if ($announcement) {
            return json(['content' => $announcement['content']]);
        } else {
            return json(['content' => 'No announcements available']);
        }
    }

    public function create()
    {
        $data = Request::post();
        Db::name('announcements')->insert($data);
        return json(['message' => 'Announcement created successfully']);
    }
}
